package com.rem.concurrency.multithreading.state;

/**
 * 线程礼让：让当前正在执行的线程暂停，但不阻塞。将线程从运行状态转化为就绪状态，让cpu重新调度。
 * @author Rem
 * @date 2021-03-03
 */

public class ThreadYield {
    public static void main(String[] args) {
        MyYield myYield = new MyYield();

        new Thread(myYield, "A").start();
        new Thread(myYield, "B").start();


    }


}

class MyYield implements Runnable {


    @Override
    public void run() {

        System.err.println(Thread.currentThread().getName() + ":   start");

        //线程礼让
        Thread.yield();

        System.err.println(Thread.currentThread().getName() + ":   end");
    }
}
